package com.laxcen.smoke.test;


import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.iot.model.v20180120.PubRequest;
import com.aliyuncs.iot.model.v20180120.PubResponse;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import org.apache.commons.codec.binary.Base64;

public class LVMe {


    public static void main(String[] args) {
        String accessKey = "LTAI5tQqhoe1XSrkoCWkDDQ9";
        String accessSecret = "MXycRe3SmNlDPKuLNt1cfxhFyjk5Cf";
        IClientProfile profile = DefaultProfile.getProfile("cn-shanghai", accessKey, accessSecret);
        DefaultAcsClient client = new DefaultAcsClient(profile);

        PubRequest request = new PubRequest();
        request.setProductKey("a12bM7wcGVy");
        request.setMessageContent(Base64.encodeBase64String("hello world".getBytes()));
        request.setTopicFullName("/a12bM7wcGVy/Oufu001/user/get");
        request.setQos(0); //目前支持QoS0和QoS1。
        try
        {
            PubResponse response = client.getAcsResponse(request);
            System.out.println(response.getRequestId());
//            System.out.println(response.getCode());
//            System.out.println(response.getSuccess());
            System.out.println(response.getErrorMessage());
        }
        catch (ServerException e)
        {
            e.printStackTrace();
        }
        catch (ClientException e)
        {
            e.printStackTrace();
        }

    }

}
